package in.muton.edushare.poll.util;

import in.muton.edushare.pages.EduShareBasePage;
import in.muton.edushare.poll.answers.AnswerBase;
import in.muton.edushare.poll.answers.CheckBoxAnswer;
import in.muton.edushare.poll.answers.DropdownAnswer;
import in.muton.edushare.poll.answers.FreeformAnswer;
import in.muton.edushare.poll.answers.PreferencesAnswer;
import in.muton.edushare.poll.answers.RadioAnswer;
import in.muton.edushare.poll.answers.RatingAnswer;
import in.muton.edushare.poll.answers.ShortTextAnswer;
import in.muton.edushare.poll.questions.CheckBoxQuestion;
import in.muton.edushare.poll.questions.DropdownQuestion;
import in.muton.edushare.poll.questions.FreeformQuestion;
import in.muton.edushare.poll.questions.PreferencesQuestion;
import in.muton.edushare.poll.questions.QuestionBase;
import in.muton.edushare.poll.questions.RadioQuestion;
import in.muton.edushare.poll.questions.RatingQuestion;
import in.muton.edushare.poll.questions.ShortTextQuestion;

import org.apache.wicket.model.IModel;

import com.edushare.common.vo.PollQuestions;

public class QuestionFactory {
	public static QuestionBase getQuestionPanel(String id,
			IModel<PollQuestions> questionModel, EduShareBasePage page,
			boolean preview, boolean editMode) {
		int qType = questionModel.getObject().getQuestionType();
		switch (qType) {
		case PollQuestions.QUESTION_TYPE_DESCRIBE:
			return new FreeformQuestion(id, questionModel, page, preview,
					editMode);
		case PollQuestions.QUESTION_TYPE_MULTIPLE_CHOICE:
			return new CheckBoxQuestion(id, questionModel, page, preview,
					editMode);
		case PollQuestions.QUESTION_TYPE_PREFERENCES:
			return new PreferencesQuestion(id, questionModel, page, preview,
					editMode);
		case PollQuestions.QUESTION_TYPE_RATING:
			return new RatingQuestion(id, questionModel, page, preview,
					editMode);
		case PollQuestions.QUESTION_TYPE_SINGLE_CHOICE:
			return new RadioQuestion(id, questionModel, page, preview, editMode);
		case PollQuestions.QUESTION_TYPE_DROPDOWN:
			return new DropdownQuestion(id, questionModel, page, preview,
					editMode);
		case PollQuestions.QUESTION_TYPE_SHORT_TEXT:
			return new ShortTextQuestion(id, questionModel, page, preview,
					editMode);
		default:
			return null;
		}
	}
	
	public static AnswerBase getAnswerPanel(String id, IModel<PollQuestions> model,
			EduShareBasePage page){
		int qType = model.getObject().getQuestionType();
		switch(qType){
		case PollQuestions.QUESTION_TYPE_DESCRIBE:
			return new FreeformAnswer(id, model, page);
		case PollQuestions.QUESTION_TYPE_MULTIPLE_CHOICE:
			return new CheckBoxAnswer(id, model, page);
		case PollQuestions.QUESTION_TYPE_PREFERENCES:
			return new PreferencesAnswer(id, model, page);
		case PollQuestions.QUESTION_TYPE_RATING:
			return new RatingAnswer(id, model, page);
		case PollQuestions.QUESTION_TYPE_SINGLE_CHOICE:
			return new RadioAnswer(id, model, page);
		case PollQuestions.QUESTION_TYPE_DROPDOWN:
			return new DropdownAnswer(id, model, page);
		case PollQuestions.QUESTION_TYPE_SHORT_TEXT:
			return new ShortTextAnswer(id, model, page);
		default:
			return null;
		}
	}
}
